<template>
  <div class="app-container">
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="时间">
        <el-col :span="11">
          <el-date-picker
            type="datetime"
            placeholder="开始时间"
            v-model="searchObj.cpHidden.createTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker
            type="datetime"
            placeholder="结束时间"
            v-model="searchObj.cpHidden.updateTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="充电站点名称">
        <el-select
          v-model="searchObj.cpHidden.addressSite"
          placeholder="充电站点名称"
          clearable
        >
          <el-option label="悠唐购物中心充电站" value="悠唐购物中心充电站" />
          <el-option
            label="广州天河体育西共享充电站1"
            value="广州天河体育西共享充电站1"
          />
        </el-select>
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="getlist()">
        查询
      </el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 列表 -->
    <el-table :data="list" border stripe>
      <el-table-column label="#" width="50">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="addressSite" label="充电站点名称" />
      <el-table-column prop="number" label="充电桩编号" />
      <el-table-column prop="address" label="地址位置" />
      <el-table-column prop="hiddenType" label="隐患类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.hiddenType === 3" type="danger" size="mini">
            重大隐患
          </el-tag>
          <el-tag
            v-else-if="scope.row.hiddenType === 1"
            type="danger"
            size="mini"
          >
            紧急隐患
          </el-tag>
          <el-tag
            v-else-if="scope.row.hiddenType === 2"
            type="danger"
            size="mini"
          >
            一般隐患
          </el-tag>
          <el-tag v-else type="danger" size="mini">类型无法确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="content" label="隐患内容" />
      <el-table-column prop="personName" label="处理人" />
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 2" type="seuccse" size="mini">
            未处理
          </el-tag>
          <el-tag v-else-if="scope.row.status === 3" type="seuccse" size="mini">
            处理中
          </el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="seuccse" size="mini">
            已处理
          </el-tag>
          <el-tag v-else-if="scope.row.status === 4" type="seuccse" size="mini">
            已完成
          </el-tag>
          <el-tag v-else type="danger" size="mini">状态无法确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="regTime" label="登记时间" />
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small">
            <router-link
              :to="
                '/charging-pile/hidden_detail/' +
                scope.row.id +
                '/' +
                scope.row.status
              "
            >
              查看
            </router-link>
          </el-button>
          <el-button type="text" size="small" @click="AddBtn(scope.row)">
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      :current-page="searchObj.pageNum"
      :total="total"
      :page-size="searchObj.pageSize"
      :page-sizes="[1, 5, 10, 15, 20]"
      style="padding: 30px 0"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="chagePage"
      @current-change="chageSize"
    />
    <DialogAdd
      @change="change"
      :editData="editData"
      :dialogVisible="dialogVisible"
    />
  </div>
</template>
<script>
import handleApi from '@/api/charging-pile/table'
import DialogAdd from '@/views/charging-pile/DialogAdd.vue'
export default {
  components: {
    DialogAdd,
  },
  data() {
    return {
      editData: {},
      dialogVisible: false,
      list: null, // 数据列表
      searchObj: {
        pageNum: 1,
        pageSize: 10,
        cpHidden: {
          createTime: '',
          updateTime: '',
          addressSite: '',
        },
      }, // 查询条件
      scope: {},
      dialogTableVisible: false, //对话框是否显示
      total: 10, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
    }
  },
  created() {
    let that = this
    let params = {
      page: that.page,
      limit: that.limit,
    }
    this.getlist(params)
  },
  methods: {
    change(dialogVisible) {
      this.dialogVisible = dialogVisible
    },
    //新增按钮
    AddBtn(val) {
      console.log(val, 'val')
      this.editData = val
      this.dialogVisible = true
    },
    getlist() {
      console.log(this.searchObj.pageNum)
      console.log(this.searchObj.pageSize)
      handleApi.findAll(this.searchObj).then((res) => {
        console.log(res, 'res')
        this.list = res.data.list
        this.total = res.data.pageTotal
      })
    },
    chagePage(res) {
      this.searchObj.pageSize = res
      this.getlist()
    },
    chageSize(res) {
      this.searchObj.pageNum = res
      this.getlist()
    },
  },
}
</script>